#include "tile.h"

Tile::Tile(const QString& name, int row, int col, TileSheet* parent)
    : QObject(parent),
      sheet_(parent),
      name_(name),
      row_(row),
      col_(col) {}

QString Tile::name() const {
  return name_;
}

QPixmap Tile::pixmap(float magnification) const {
  QPixmap pixmap = sheet_->pixmap().copy(col_ * sheet_->tileSize().width(),
                                         row_ * sheet_->tileSize().height(),
                                         sheet_->tileSize().width(),
                                         sheet_->tileSize().height());
  if (magnification != 1.0f) {
    pixmap = pixmap.scaled(pixmap.width() * magnification, pixmap.height() * magnification);
  }
  return pixmap;
}

QIcon Tile::icon(float magnification) const {
  QIcon ret;
  ret.addPixmap(pixmap(magnification));
  return ret;
}

QPoint Tile::position() const {
  return QPoint(col_, row_);
}
